package com.wms.common.util;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

public class ConfFileTool {
	private static ConfFileTool confFileTool = null;
	private static Properties properties = null;
	
	private ConfFileTool() throws Exception{
		if(null==properties) properties = new Properties();
		String path = System.getenv("CI_CONFDIR")+ File.separator + "ci.conf";
		Properties p = readConfig(path);
		properties.putAll(p);
	}
	
	public static ConfFileTool getInstance() throws Exception{
		if(null == confFileTool) {
			confFileTool = new ConfFileTool();
		}
		return confFileTool;
	}
	
	public String getProperty(String key){
		return (String)properties.get(key);
	}
	
	private Properties readConfig(String filePath) throws Exception{
		Properties property = new Properties();
		FileInputStream inputFile = null;
        try {
        	inputFile = new FileInputStream(filePath);
        	property.load(inputFile);
        } catch (Exception ex) {
            throw ex;
        } finally {
            if(null!=inputFile) 
            	inputFile.close();
        }
        return property;
    }
}
